<?php
namespace app\admin\controller;
use think\Db;
use think\Request;
class Banner extends Common
{
    public function index(){
        if(request()->isPost()) {
			$time = input('post.time');
            $key = input('post.key');
			$where=array();	
			if($key){
				$where['title'] = ['like','%'.$key.'%'];
			}
            $page =input('page')?input('page'):1;
            $pageSize =input('limit')?input('limit'):config('common.page_sizes');
            $list = db('banner')
                ->where($where)
                ->order('id desc')
                ->paginate(array('list_rows'=>$pageSize,'page'=>$page))
                ->toArray();
			$list = model('banner')->listAddTimeInfo($list);	
			return $result = ['code'=>0,'msg'=>config('common.data_success'),'data'=>$list['data'],'count'=>$list['total'],'rel'=>1];
		}
        return $this->fetch('');
    }
    // 配套设施修改
    public function edit(){
        if(request()->isPost()){
            $data = input('post.');
            return model('banner')->commonData($data,'修改成功!','修改失败，请重试!');
        }else{
            $id = input('id');
            $list =db('banner')->where(['id'=>$id])->find();
            return $this->fetch('',['list'=>$list]);
        }
        
    }
    // 配套设施添加
    public function add(){
        if(request()->isPost()){
            $data = input('post.');
            $data['addtime'] = time();
            return model('banner')->commonData($data,'添加成功','添加失败，请重试');
        }else{
            return $this->fetch('');
        }
    }
    public function del(){
        if(request()->isPost()){
            $data = input('post.')['id'];
            return model('banner')->commonDel($data,'删除成功','删除失败，请重试');
        }
    }
     public function status()
    {
        if (request()->isPost()) {
            $data = input('post.');
            return model('banner')->commonState($data, '状态更变成功', '状态更变失败，请稍后重试');

        }
    }


}
